package com.sl.hx.shop.http;

/**
 * 错误码转换成相应的错误信息
 *
 * Created by hwg on 2017/12/20.
 */

public class ApiException extends RuntimeException {


    public static final int TOKEN_FAILED = 1001 ;   //token过期
    public static final int NO_TOKEN = -1 ;
    public static final int NO_BAND_USER = 3000 ;   //第三方登录时未绑定用户

    private static String message ;
    private int code ;

    public ApiException(int code){
        this(getApiExceptionMessage(code)) ;
        this.code = code ;
    }

    public ApiException(String detailMessage){
        message = detailMessage ;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public int getCode(){
        return code ;
    }

    /**
     * 将服务端返回的判断码转换成详细的提示信息
     * @param code
     * @return
     */
    private static String getApiExceptionMessage(int code){

        //根据实际情况修改
        switch (code){
            case TOKEN_FAILED :
                message = "登录已失效，请重新登录" ;
                break;

        }
        return message ;
    }
}
